﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebCrawler.Graph.Interfaces;

namespace WebCrawler.Graph
{
    class SimpleGraph : IBasicGraph
    {
        List<IVertex> _vertices;

        public SimpleGraph()
        {
            _vertices = new List<IVertex>();
        }

        public void AddVertex(IVertex vertex)
        {
            _vertices.Add(vertex);
        }

        public void AddEdge(IVertex from, IVertex to)
        {
            foreach (var IVertex in _vertices)
            {
                if (IVertex == from)
                {
                    IVertex.Edges.Add(new Edge(from, to));
                    return;
                }
            }
        }

        public void RemoveVertex(IVertex IVertex)
        {
            foreach (var vert in _vertices)
            {
                foreach (Edge edge in vert.Edges)
                {
                    if (edge.To == IVertex)
                    {
                        vert.Edges.Remove(edge);
                    }
                }
            }

            _vertices.Remove(IVertex);
        }

        public void RemoveEdge(IVertex from, IVertex to)
        {
            foreach (var IVertex in _vertices)
            {
                if (IVertex == from)
                {
                    foreach (var item in IVertex.Edges)
                    {
                        if (item.To == to)
                        {
                            IVertex.Edges.Remove(item);
                        }
                    }
                }
            }
        }

        public bool ContainsVertex(IVertex vertex)
        {
            return _vertices.Any(p => p == vertex);
        }

        public bool IsAdjacent(IVertex from, IVertex to)
        {
            foreach (var item in _vertices)
            {
                if (item == from)
                {
                    foreach (var edge in item.Edges)
                    {
                        if (edge.To == to)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }

        public System.Collections.IList GetAdjacencies(IVertex IVertex)
        {
            throw new NotImplementedException();
        }

        public System.Collections.IEnumerator Vertices()
        {
            throw new NotImplementedException();
        }

        public IList<IVertex> VerticesAsList()
        {
            throw new NotImplementedException();
        }

        public System.Collections.IEnumerator Edges()
        {
            throw new NotImplementedException();
        }

        public bool IsEmpty()
        {
            throw new NotImplementedException();
        }

        public int GetNoOfVertices()
        {
            throw new NotImplementedException();
        }

        public int GetNoOfEdges()
        {
            throw new NotImplementedException();
        }

        public void Clear()
        {
            throw new NotImplementedException();
        }

        public System.Collections.IList DfsIterative(IVertex IVertex)
        {
            throw new NotImplementedException();
        }

        public System.Collections.IList DfsRecursive(IVertex IVertex)
        {
            throw new NotImplementedException();
        }

        public System.Collections.IList BfsIterative(IVertex IVertex)
        {
            throw new NotImplementedException();
        }
    }
}
